const { sequelize } = require("../../core/db");
const { Sequelize, Model } = require("sequelize");

// 定义积分操作记录
class PointRecord extends Model {}
PointRecord.init(
  {
    point_record_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    uid: Sequelize.INTEGER,
    operator_id: {
      type: Sequelize.INTEGER,
      defaultValue: 0,
      comment: "操作员id",
    },
    operation: {
      type: Sequelize.STRING,
      comment: "操作记录",
    },

    current_point: {
      type: Sequelize.STRING,
      comment: "当前积分",
    },
    // point: {
    //   type: Sequelize.INTEGER,
    //   comment: "积分",
    // },
    add_point: {
      type: Sequelize.INTEGER,
      comment: "增加积分",
    },
    remove_point: {
      type: Sequelize.INTEGER,
      comment: "减少积分",
    },
    remark: {
      type: Sequelize.STRING,
      comment: "备注",
    },
  },
  {
    sequelize,
    tableName: "point_record",
  }
);

// 定义获取积分模型
class UserPoint extends Model {}
UserPoint.init(
  {
    user_point_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    uid: Sequelize.INTEGER,
    operator_id: {
      type: Sequelize.INTEGER,
      comment: "操作员id",
    },
    // operator_name: {
    //   type: Sequelize.STRING,
    //   comment: "操作员名字",
    // },
    point: {
      type: Sequelize.INTEGER,
      comment: "积分",
    },
    remark: {
      type: Sequelize.STRING,
      comment: "备注",
    },
  },
  {
    sequelize,
    tableName: "user_point",
  }
);

module.exports = {
  UserPoint,
  PointRecord,
};
